package aufgabe2;

import java.util.*;

/**
 * definition of a Student-object
 * 
 * @author Lukas Koell
 * @author David Medenjak
 * @author Johannes Riedmann
 */
public class Student extends User {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    /** Matrikel-Number of the student */
    private int matrikelNr;

    /** a list of courses that the student has completed **/
    private HashMap<Course, Grade> completedCourses;

    public Student(int matrikelNr, String name) {
        completedCourses = new HashMap<Course, Grade>();
        this.matrikelNr = matrikelNr;
        setName(name);
    }

    /**
     * getter-method for MatrikelNr
     * 
     * @return MatrikelNr of a student
     */
    public int getMatrikelNr() {
        return matrikelNr;
    }

    /**
     * defines toString-Method for Student-objects
     * 
     * @return formated representation of a Student-object
     */
    @Override
    public String toString() {
        return this.getMatrikelNr() + ": " + getName() + "\n";
    }

    /**
     * @return the completedCourses
     */
    public Map<Course, Grade> getCompletedCourses() {
        return completedCourses;
    }

    /**
     * @param completedCourses
     *            the completedCourses to set
     */
    public void addCompletedCourse(Course course, Grade grade) {
        this.completedCourses.put(course, grade);
    }

    /**
     * when a student is updated by an observable, only StudentNotifications
     * will be handled. Everything else will be ignored
     */
    @Override
    public void update(Observable o, Object arg) {
        // we only want to handle studentNotifications here! RAWR!
        if (arg instanceof StudentNotification) {
            notifications.add(arg.toString());
        }
    }

    public int getId() {
        return matrikelNr;
    }
}
